#include "descriptionTab.h"
//#include <QGroupBox>

DescriptionTab::DescriptionTab(){
//setMaximumHeight(100); //da mettere piu flessibile 
  filesList = new KTextEdit();
  filesList->setReadOnly(true);
  layout = new QVBoxLayout(this);
  setLayout(layout);
  layout->addWidget(filesList);
  QString text;
  text.sprintf("<br><html><head><syle type='text/css'/> </head><body><h3><center>Update the packages list and select a package to see informations about it.</center><br></h3></body></html>");
  filesList->clear();
  filesList->append(text);
  filesList->moveCursor(QTextCursor::Start);
}

DescriptionTab::~DescriptionTab() {
}

void DescriptionTab::setDescription(map<string,string> description) {
// setta la descrizione nel KTextEdit
  map<string,string>::iterator iter;
  iter=description.find("Package");
  const char *nm = iter->second.c_str();

  QString text;
  text.sprintf("<html><head><syle type='text/css'/> </head><body><h3> Package <font color='#636363'> %s </font>is currently installed in your system.<br></h3><h4><bold><table>", nm);

  QString key;
  QString value;

  iter=description.find("Version");
  const char *ver = iter->second.c_str();
  text.append("<tr><td> Package:</td><td width='15'/><td><font color='#636363'> " + QString(nm) + " </font></td></tr>");
  text.append("<tr><td> Version:</td><td width='15'/><td><font color='#636363'> " + QString(ver) + " </font></td></tr>");

  for( iter = description.begin(); iter != description.end(); iter++ ) {
    if(!iter->first.compare("Package") ||  !iter->first.compare("Version")) continue;
    key = QString(iter->first.c_str());
    value = QString(iter->second.c_str());

    value.replace(QString("\n"),QString("<br>"));
    text.append("<tr><td>" + key + ":</td><td width='15'/><td><font color='#636363'> " + value + " </font></td></tr>");
  }
  text.append("</table></body></html>");

  filesList->clear();
  filesList->append(text);
  filesList->moveCursor(QTextCursor::Start);
}
